package com.easy.util;

import java.util.Date;

/**
 * @author wxk
 * @Description: TODO
 * @date 2021/7/7
 */
public class ValidationCode {

    public final static String VALID_CODE_NAME = "VALIDCODE";

    private String code;

    private Date createTime;

    private int expireMillisecond = 6000;

    private ValidationCode(String code) {
        this.code = code;
        this.createTime = new Date();
    }

    public static ValidationCode create(String code) {
        return new ValidationCode(code);
    }

    /**
     * 是否过期
     */
    public boolean isExpired() {
        Long between_Millisecond = new Date().getTime() - createTime.getTime();
        return between_Millisecond.intValue() > expireMillisecond;
    }

    /**
     * 与客户端code比较是否一致
     */
    public boolean valid(String newCode) {
        return this.code.equalsIgnoreCase(newCode);
    }
}
